package db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;

public class ServiceDatabase extends SQLiteAssetHelper {
	private static final int DATABASE_VERSION = 1;

	public ServiceDatabase(Context context) {
		super(context, "keepfriend.db", null, DATABASE_VERSION);
	}

	public void updateSeen(String phone, String seen_event) {
		SQLiteDatabase db = getReadableDatabase();
		try {
			String sql = "UPDATE friends" + " SET seen_datetime = CURRENT_TIMESTAMP, seen_event = '" + seen_event + "', is_seen = 1" + " WHERE phone='" + phone + "'";
			db.execSQL(sql);
		} catch (Exception e) {
			Log.e("EXCEPTION", e.getMessage());
		} finally {
			db.close();
		}
	}

	public static String refinePhone(String phone) {
		return phone.replace("+84", "0").replaceAll("[^0-9+]", "");
	}
}
